<template>
	<view>
		<view class="s-safe-area">
			<view class="s-address">
				<block v-for="(item,index) in list" :key="index">
					<s-list-cell padding="0">
						<view class="s-address-flex" @tap="status(index)">
							<view class="s-address-left">
								<view class="s-address-main">
									<view class="s-address-name">{{item.name}}</view>
									<view class="s-address-tel">{{item.phone}}</view>
								</view>
								<view class="s-address-detail">
									<view v-if="item.status" class="s-address-label">默认</view>
									<text>{{item.province_name}}{{item.city_name}}{{item.county_name}}{{item.detailed_address}}</text>
								</view>
							</view>
							<view class="s-address-imgbox" @tap.stop="edit_address(item.id)">
								<s-icon name="bianji" color="#999" :size="44" unit="rpx"></s-icon>
							</view>
						</view>
					</s-list-cell>
				</block>
				<s-no-data v-if="list.length<=0&&isData" :imgUrl="$s.config.getConfig('NoDataImgUrlA')">
					{{$s.config.getConfig('NoDataTitle')}}
				</s-no-data>
				<!-- 新增地址 -->
				<view class="s-address-new">
					<s-button type="danger" height="88upx" @click="add_address">+ 新增收货地址</s-button>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				isData:false,
				list:[] //我的地址列表
			}
		},
		onShow() {
			this._onLoad()
		},
		methods: {
			async _onLoad(){
				this.list = await this.$s.model.address.getAddressList()
				this.isData = true
			},
			//添加地址
			async add_address(){
				return await this.$s.uniApi.navigateTo({url:'../add_address/add_address'})
			},
			//编辑地址
			async edit_address(id){
				return await this.$s.uniApi.navigateTo({url:'../edit_address/edit_address?id='+id})
			},
			async status(index){
				if(this.list[index].status === 1){
					return
				}
				await this.$s.model.address.status({id:this.list[index].id})
				await this._onLoad()
			}
		},
		//下拉刷新
		async onPullDownRefresh() {
		    await this._onLoad()
		    uni.stopPullDownRefresh()   
		}  
	}
</script>
<style lang="scss" scoped>
@import 'address.scss';
</style>
